package com.taptech.doufu.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.taptech.doufu.R;
import com.taptech.doufu.bean.TipInfo;

public class TipDialog extends Dialog implements android.view.View.OnClickListener{
	private TextView tipContent,titleTv,sureName,cancelName;

	protected TipInfo tipInfo;

	public TipDialog(Context context) {
		super(context);
	}
	 
	public TipDialog(Context context,int theme,TipInfo tipInfo) {
		super(context,theme);
		this.tipInfo=tipInfo;
	}

	ImageView exitDialogBtn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_tip_layout);
		tipContent=(TextView)findViewById(R.id.dialog_tip_layout_tip);
		tipContent.setText(tipInfo.getTipContent());
		titleTv=(TextView)findViewById(R.id.dialog_tip_layout_title);

		exitDialogBtn = (ImageView) findViewById(R.id.exit_dialog_btn);
		exitDialogBtn.setOnClickListener(this);
		if (tipInfo.getTitle()!=null) {
			titleTv.setVisibility(View.VISIBLE);
			titleTv.setText(tipInfo.getTitle());
		}
		sureName=(TextView)findViewById(R.id.dialog_tip_layout_sure);
		cancelName=(TextView)findViewById(R.id.dialog_tip_layout_cancel);
		cancelName.setOnClickListener(this);
		sureName.setOnClickListener(this);
		if (tipInfo.getSureName()!=null&&tipInfo.getCancelName()!=null) {
			sureName.setText(tipInfo.getSureName());
			cancelName.setText(tipInfo.getCancelName());

		}
		if (tipInfo.hasExit){
			exitDialogBtn.setVisibility(View.VISIBLE);
		}else {
			exitDialogBtn.setVisibility(View.GONE);
		}

	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int flag=0;
		switch (v.getId()) {
		case R.id.dialog_tip_layout_sure:
			flag=1;
			break;
		case R.id.dialog_tip_layout_cancel:
			flag=0;
			break;
		default:
			break;
		}
		dismiss();
		if (tipInfo.getTipListener()!=null) {
			tipInfo.getTipListener().resultBack(flag,tipInfo.getType());
		}
	}

}
